/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.serli.sample.person.model.service.ejb;

import com.serli.sample.person.model.data.Gender;
import com.serli.sample.person.model.data.Person;
import com.serli.sample.person.model.service.PeopleServiceRemote;
import com.serli.sample.person.model.data.session.PeopleBeanLocal;
import java.text.ParseException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.ejb.Remote;
import javax.ejb.Stateless;

/**
 * Un service EJB remote permettant de manipuler les données d'un 
 * objet de type <code>Person</code>.
 * 
 * @author serli
 */
@Stateless ( name= "PeopleService-RMI" )
@Remote(value={PeopleServiceRemote.class})
public class PeopleService  implements PeopleServiceRemote {

    @EJB ( name= "people-model-ear-1.1/PeopleBean/local" )
    PeopleBeanLocal peopleBean = null;
      
    @Override
    public void insert(Person person) {
        peopleBean.insert(person);
    }
    
    @Override
    public void delete(Person person) {
        peopleBean.delete(person);
    }
    
    @Override
    public List<Person> getAllOrderByFirstName() {
        return peopleBean.getAllOrderByFirstName();
    }

    @Override
    public void testRemoteSetPerson(Person person) {
        System.out.println(person.toString());
    }

    @Override
    public Person testRemoteGetPerson()  {
        try {
            return new Person("TestFirstName-ejb", "TestLastName-ejb", "1979-01-17", Gender.MALE);
        } catch (ParseException ex) {
            Logger.getLogger(PeopleService.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }
    }    
    
    @Override
    public Object testRemoteObject(Object obj) {
        return obj;
    }

    @Override
    public int testRemotePrimitif(int i) {
        return i;
    }
}